package viewmodel;

import componentes.CommunicationManager;

import items.BetItem;
import android.app.betmein.R;
import android.app.betmein.activity.DisplayBetActivity;
import android.app.betmein.view.BetManagementWatchListTabView;
import android.app.betmein.view.ViewCreatorHelper;
import android.content.Context;
import android.framework.binding.BindableList;
import android.framework.binding.Binding;
import android.framework.binding.ItemList;
import android.framework.paging.BaseViewModel;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

public class BetManagementWatchListTabViewModel extends BaseViewModel<BetManagementWatchListTabView>{

	private ItemList<BetItem> bets;
	
	public BetManagementWatchListTabViewModel(Context context) {
		super(context);
		bets = new ItemList<BetItem>(context, R.layout.single_watchlist_bet, ViewCreatorHelper.judgmentBetListViewCreator());
	}

	@Override
	public void onInit() {
		getView().bets.setOnItemClickListener(new OnItemClickListener() {
			
			public void onItemClick(AdapterView<?> adapter, View arg1, int pos,
					long arg3) {
				BetItem betItem = (BetItem)adapter.getItemAtPosition(pos);
				startActivity(DisplayBetActivity.class, betItem.getBet());
			}
		});
		getView().bets.setAdapter(bets);
		
		BindableList<BetItem> watchListBets = CommunicationManager.getInstance().getWatchListBets();
		bets.addAll(watchListBets);
		Binding.attached(watchListBets, bets);
	}

}
